import asyncio
from common.base.base_handler import BaseHandler
from services.server_integration.schemas.calibrate_status import CalibrateMessage
from settings import settings


class ServerIntegrationRouterHandler(BaseHandler):
    __slots__ = ['cg_queues']

    def __init__(self) -> None:
        super(ServerIntegrationRouterHandler, self).__init__(request_queue_uuid=settings.SERVER_INTEGRATION_ROUTER_REQUEST_QUEUE)
        self.cg_queues: dict[int, asyncio.Queue] = dict()
        self.handle('set_calibrate_status', self.handle_set_calibrate_status)

    async def handle_set_calibrate_status(self, params: dict):
        msg = CalibrateMessage(**params['msg'])
        for queue in self.cg_queues.values():
            await queue.put(msg)

        return True
